package com.tudouji.project.flow.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tudouji.framework.aspectj.lang.annotation.Log;
import com.tudouji.framework.aspectj.lang.enums.BusinessType;
import com.tudouji.project.flow.domain.FlowTask;
import com.tudouji.project.flow.service.IFlowTaskService;
import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.common.utils.poi.ExcelUtil;
import com.tudouji.framework.web.page.TableDataInfo;

/**
 * 流程任务Controller
 * 
 * @author tudouji
 * @date 2022-06-20
 */
@RestController
@RequestMapping("/flow/task")
public class FlowTaskController extends BaseController
{
    @Autowired
    private IFlowTaskService flowTaskService;

    /**
     * 查询流程任务列表
     */
    @PreAuthorize("@ss.hasPermi('flow:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(FlowTask flowTask)
    {
        startPage();
        List<FlowTask> list = flowTaskService.selectFlowTaskList(flowTask);
        return getDataTable(list);
    }

    /**
     * 导出流程任务列表
     */
    @PreAuthorize("@ss.hasPermi('flow:task:export')")
    @Log(title = "流程任务", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FlowTask flowTask)
    {
        List<FlowTask> list = flowTaskService.selectFlowTaskList(flowTask);
        ExcelUtil<FlowTask> util = new ExcelUtil<FlowTask>(FlowTask.class);
        return util.exportExcel(list, "task");
    }

    /**
     * 获取流程任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('flow:task:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(flowTaskService.selectFlowTaskById(id));
    }

    /**
     * 新增流程任务
     */
    @PreAuthorize("@ss.hasPermi('flow:task:add')")
    @Log(title = "流程任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FlowTask flowTask)
    {
        return toAjax(flowTaskService.insertFlowTask(flowTask));
    }

    /**
     * 修改流程任务
     */
    @PreAuthorize("@ss.hasPermi('flow:task:edit')")
    @Log(title = "流程任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FlowTask flowTask)
    {
        return toAjax(flowTaskService.updateFlowTask(flowTask));
    }

    /**
     * 删除流程任务
     */
    @PreAuthorize("@ss.hasPermi('flow:task:remove')")
    @Log(title = "流程任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(flowTaskService.deleteFlowTaskByIds(ids));
    }

    /**
     * 查询待处理列表
     */
    @GetMapping("/pendingList")
    public TableDataInfo pendingList(FlowTask flowTask)
    {
        startPage();
        List<FlowTask> list = flowTaskService.selectPendingList(flowTask);
        return getDataTable(list);
    }
}
